package roosterparser;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;

public class Rooster {
	private String faculteit;
	private String opleiding;
	private String groep;
	private ArrayList<Cursus> cursussen;
	
	public Rooster(String faculteit, String opleiding, String groep) {
		this.faculteit = faculteit;
		this.opleiding = opleiding;
		this.groep = groep;
		this.cursussen = new ArrayList<Cursus>();
	}
	
	public Rooster(String faculteit) {
		this.faculteit = faculteit;
		this.cursussen = new ArrayList<Cursus>();
	}

	public String getFaculteit() {
		return faculteit;
	}
	public void setFaculteit(String faculteit) {
		this.faculteit = faculteit;
	}
	public String getOpleiding() {
		return opleiding;
	}
	public void setOpleiding(String opleiding) {
		this.opleiding = opleiding;
	}
	public String getGroep() {
		return groep;
	}
	public void setGroep(String groep) {
		this.groep = groep;
	}
	
	public void addCursus(Cursus cursus) {
		cursussen.add(cursus);
	}
	
	public void toGCalCSVImport() throws Exception {
		FileOutputStream fos = new FileOutputStream("rooster.csv");
		PrintWriter fw = new PrintWriter(fos);
		
		fw.println("Subject,Start Date,Start Time,End Date,End Time,Description,Location");
		
		for (Cursus cursus : cursussen) {
			StringBuilder sb = new StringBuilder();
			sb.append(cursus.getOpmerkingen());
			sb.append(",");
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd,HH:mm");
			sb.append(df.format(cursus.getStartDatum().getTime()));
			sb.append(",");
			
			sb.append(df.format(cursus.getEindDatum().getTime()));
			sb.append(",\"");
			
			boolean first = true;
			for (String docent : cursus.getDocenten()) {
				if (first) {
					first = false;
				} else {
					sb.append(", ");
				}
				sb.append(docent);
			}
			sb.append("\",\"");
			
			sb.append(cursus.getLokaal());
			sb.append("\"");
			fw.println(sb.toString());
		}
		
		fw.close();
	}
}
